<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
    <TITLE>Stream Offsets</TITLE>
    <LINK REL="stylesheet" HREF="../../../../boost.css">
    <LINK REL="stylesheet" HREF="../theme/iostreams.css">
</HEAD>
<BODY>

<!-- Begin Banner -->

    <H1 CLASS="title">Stream Offsets</H1>
    <HR CLASS="banner">

<!-- End Banner -->

<DL class="page-index">
  <DT><A href="#overview">Overview</A></DT>
  <DT><A href="#acknowledgments">Acknowledgments</A>
  <DT><A href="#headers">Headers</A></DT>
  <DT><A href="#reference">Reference</A></DT>
</DL>

<HR>

<A NAME="overview"></A>
<H2>Overview</H2>

<P>
    The header <A CLASS="header" HREF="../../../../boost/iostreams/positioning.hpp"><CODE>&lt;boost/iostreams/positioning.hpp&gt;</CODE></A> provides the definition of the integral type <CODE>boost::iostreams::stream_offset</CODE>, capable of holding arbitrary stream offsets on most platforms, together with the definition of two functions, <CODE>offset_to_position</CODE> and <CODE>position_to_offset</CODE>, for converting between <CODE>stream_offset</CODE> and <CODE>std::streampos</CODE>.
</P>

<P>
    The type <CODE>std::streampos</CODE> is required to be able to hold an arbitrary stream position, but it is not an intergral type. Although <CODE>std::streampos</CODE> is interconvertible with the integral type <CODE>std::streamoff</CODE>, the conversion from <CODE>std::streampos</CODE> to <CODE>std::streamoff</CODE> may not be faithful for large (64-bit) values. The integral type <CODE>boost::iostreams::stream_offset</CODE> is intended as a replacement for <CODE>std::streamoff</CODE>, with the implicit conversions to and from <CODE>std::streampos</CODE> being replaced by explicit conversion functions.
</P>

<P>
    The implementation of <CODE>offset_to_position</CODE> and <CODE>position_to_offset</CODE> relies on implementation defined behavior, and is guaranteed to work correctly for large values only for standard libraries which define <CODE>std::streamoff</CODE> to be 64-bit type or for which the Boost Iostreams library has been explicitly configured.
</P>

<A NAME="acknowledgments"></A>
<H2>Acknowledgments</H2>

<P>Gareth Sylvester-Bradley suggested the treatment of large stream offsets used by the Boost Iostreams library and supplied the implementation of <CODE>offset_to_position</CODE> and <CODE>position_to_offset</CODE> used with the Dinkumware standard library.</P>

<A NAME="headers"></A>
<H2>Headers</H2>

<DL class="page-index">
  <DT><A CLASS="header" HREF="../../../../boost/iostreams/positioning.hpp"><CODE>&lt;boost/iostreams/positioning.hpp&gt;</CODE></A></DT>
</DL>

<A NAME="reference"></A>
<H2>Reference</H2>

<A NAME="synopsis"></A>
<H4>Synopsis</H4>

<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {

<SPAN CLASS='keyword'>typedef</SPAN> <A CLASS='documented' HREF='../../../integer/doc/html/boost_integer/cstdint.html' TARGET='_top'>boost::intmax_t</A> stream_offset;
std::streampos <A CLASS='documented' HREF='#offset_to_position'>offset_to_position</A>(stream_offset n);
stream_offset <A CLASS='documented' HREF='#position_to_offset'>position_to_offset</A>(std::streampos pos);

} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></PRE>

<A NAME="offset_to_position"></A>
<H4>Function template <CODE>offset_to_position</CODE></H4>

<PRE CLASS="broken_ie">std::streampos offset_to_position(stream_offset n);</PRE>

<P>Returns a <CODE>std::streampos</CODE> representing the <CODE>n</CODE><I>th</I> position in a stream.</P>

<A NAME="position_to_offset"></A>
<H4>Function template <CODE>position_to_offset</CODE></H4>

<PRE CLASS="broken_ie">stream_offset position_to_offset(std::streampos pos);</PRE>

<P>Returns a <CODE>stream_offset</CODE> representing the same character position as <CODE>pos</CODE>, disregarding any code-conversion state.</P>

<!-- Begin Footer -->

<HR>

<P CLASS="copyright">&copy; Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a><br/>&copy; Copyright 2004-2007 <a href="https://www.boost.org/users/people/jonathan_turkanis.html" target="_top">Jonathan Turkanis</a></P>
<P CLASS="copyright"> 
    Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <A HREF="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>)
</P>

<!-- End Footer -->

</BODY>